<template>
  <div class="login-container">
    <!-- 标题 -->
    <div class="title">用户登录</div>
    
    <!-- 注册提示 -->
    <div class="register-tip">
      还没有账户 <a href="/register" class="register-link">去注册>></a>
    </div>

    <!-- 登录表单 -->
    <div class="login-form">
      <!-- 账号输入框 -->
      <div class="input-group">
        <div class="input-label">账号（手机号）</div>
        <div class="input-wrapper">
          <i class="iconfont icon-mobile"></i> <!-- 假设使用字体图标 -->
          <input 
            type="text" 
            v-model="loginForm.mobile" 
            placeholder="请输入手机号码"
            class="input-field"
          />
        </div>
      </div>

      <!-- 密码输入框 -->
      <div class="input-group">
        <div class="input-label">密码</div>
        <div class="input-wrapper">
          <i class="iconfont icon-lock"></i> <!-- 假设使用字体图标 -->
          <input 
            type="password" 
            v-model="loginForm.password" 
            placeholder="请输入密码"
            class="input-field"
          />
          <a href="javascript:;" class="forget-password">忘记密码</a>
        </div>
      </div>

      <!-- 登录按钮 -->
      <button class="login-btn" @click="handleLogin">登录</button>
    </div>
  </div>
</template>

<script setup>
import { reactive } from 'vue';
import { ElMessage } from 'element-plus'; // 如果使用 Element Plus
import { useLoginStore } from '@/store/modules/login'; // Pinia 状态管理

const loginForm = reactive({
  mobile: '',
  password: ''
});

const loginStore = useLoginStore();

const handleLogin = () => {
  if (!loginForm.mobile || !loginForm.password) {
    ElMessage.warning('请填写账号和密码');
    return;
  }
  // 调用 Pinia Store 的登录方法
  loginStore.login(loginForm).then(success => {
    if (success) {
      ElMessage.success('登录成功');
      // 跳转到首页（假设首页路由是 `/`）
      window.location.href = '/';
    } else {
      ElMessage.error('账号或密码错误');
    }
  });
};
</script>

<style scoped lang="scss">
.login-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  padding: 20px;

  .title {
    font-size: 28px;
    font-weight: bold;
    margin-bottom: 16px;
    color: #333;
  }

  .register-tip {
    font-size: 14px;
    color: #666;
    margin-bottom: 30px;

    .register-link {
      color: #409EFF;
      text-decoration: none;
      margin-left: 4px;
    }
  }

  .login-form {
    width: 100%;
    max-width: 400px;
    background: #fff;
    padding: 30px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);

    .input-group {
      margin-bottom: 20px;

      .input-label {
        font-size: 14px;
        color: #666;
        margin-bottom: 8px;
      }

      .input-wrapper {
        display: flex;
        align-items: center;
        border: 1px solid #dcdfe6;
        border-radius: 4px;
        padding: 0 12px;

        .iconfont {
          font-size: 18px;
          color: #409EFF;
          margin-right: 8px;
        }

        .input-field {
          flex: 1;
          height: 45px;
          border: none;
          outline: none;
          font-size: 14px;
        }
      }
    }

    .forget-password {
      margin-left: auto;
      font-size: 14px;
      color: #909399;
      text-decoration: none;
    }

    .login-btn {
      width: 100%;
      height: 45px;
      background: #409EFF;
      color: #fff;
      border: none;
      border-radius: 4px;
      font-size: 16px;
      cursor: pointer;
      margin-top: 10px;

      &:hover {
        background: #66b1ff;
      }
    }
  }
}
</style>